package com.example.aqarapp.view.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.Toast;

import aqarapp.R;

public class UserPopupWindow extends PopupWindow implements View.OnClickListener {

    private static final String UserAndSecrecyTitle = "使用条款&隐私政策";
    private static final String SoundServiceTitle = "语音服务";

    private Context mContext;
    private RelativeLayout policyLayout, voiceServiceLayout;
    private Button mLoginOutBtn;
    private String termsText = "这是内容";
    private UserInfoDialog mUserInfoDialog;
    private ImageView mQuitIv;

    public UserPopupWindow(View contentView, int width, int height) {
        super(contentView, width, height);
        mContext = getContentView().getContext();
        initView();
    }

    private void initView() {
        policyLayout = getContentView().findViewById(R.id.policy_view);
        voiceServiceLayout = getContentView().findViewById(R.id.voice_service_view);
        mLoginOutBtn = getContentView().findViewById(R.id.login_out_btn);
        for (int i = 0; i < 100; i++) {
            termsText = termsText + "这是内容";
        }
        policyLayout.setOnClickListener(this);
        voiceServiceLayout.setOnClickListener(this);
        mLoginOutBtn.setOnClickListener(this);
    }

    private void showUserInfoDialog(String title, String content) {
        mUserInfoDialog = new UserInfoDialog(mContext, title, content);
        mUserInfoDialog.show();
        mQuitIv = mUserInfoDialog.getWindow().findViewById(R.id.dialog_quit_iv);
        mQuitIv.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.policy_view:
                showUserInfoDialog(UserAndSecrecyTitle, termsText);
                break;
            case R.id.voice_service_view:
                showUserInfoDialog(SoundServiceTitle, termsText);
                break;
            case R.id.dialog_quit_iv:
                mUserInfoDialog.hide();
                break;
            case R.id.login_out_btn:
                //todo 退出登录需要进行的逻辑
                Toast.makeText(mContext, "退出登录", Toast.LENGTH_LONG).show();
                break;
            default:
                break;
        }
    }

    public UserInfoDialog getUserInfoDialog() {
        return mUserInfoDialog;
    }
}
